var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    TimeProduct: [],
    CurrentPage: 1,
    loadingMoreHidden: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getTimeProductList()
  },
  toDetailsTap:function(e){
    wx.navigateTo({
      url: '/pages/goods-details/index?id=' + e.currentTarget.dataset.id,
    })
  },
  /**
   * 获取限时商品列表
   */
  getTimeProductList: function () {
    var that = this
    wx.request({
      url: app.globalData.host + '/api/Store/TimeProductList?storeId=' + app.globalData.storeId + '&pageSize=' + 15 + '&pageNumber=' + that.data.CurrentPage,
      success: function (res) {
        console.log(res)
        if (res.data.Code == 0) {
          var ProductList = res.data.Data.TimeProductList
          var rawData = res.data.Data.PageModel;
          for (var i = 0; i < ProductList.length; i++) {
            if (ProductList[i].showimg){
              ProductList[i].showimg = app.globalData.image800_800host + ProductList[i].showimg
            }
          }
          if (that.data.CurrentPage != 1) {
            var preGoods = that.data.TimeProduct
            ProductList = preGoods.concat(ProductList);
          }
          that.setData({
            TimeProduct: ProductList,
            loadingMoreHidden: rawData.HasNextPage
          })
        }
      }
    })
  },
  /**
 * 加载更多
 */
  loadMore: function (e) {
    var that = this;
    if (!that.data.loadingMoreHidden) return;
    var currPage = that.data.CurrentPage;
    that.setData({
      CurrentPage: currPage + 1
    })
    that.getTimeProductList();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})